<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>FCKDataProcessor - Tests for JsUnit</title>
	<script src="../../../editor/_source/fckscriptloader.js" type="text/javascript"></script>
	<script type="text/javascript" src="tests.js"></script>
	<script type="text/javascript" src="../_jsunit/app/jsUnitCore.js"></script>
	<script type="text/javascript">

var FCK =
{
	IsDirty : function() { return true ; }
}

FCKScriptLoader.Load( 'FCKDataProcessor' ) ;

	</script>
	<script src="../../../fckconfig.js" type="text/javascript"></script>
	<script type="text/javascript">

function test_ConvertToHtml()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<html dir="ltr"><head><title></title></head><body>This is some <strong>sample text</strong>.</body></html>',
		dataProcessor.ConvertToHtml( 'This is some <strong>sample text</strong>.' ) ) ;
}

function test_ConvertToHtml_Empty()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<html dir="ltr"><head><title></title></head><body></body></html>',
		dataProcessor.ConvertToHtml( '' ) ) ;
}

function test_ConvertToHtml_Full()
{
	FCKConfig.FullPage = true ;

	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<html dir="rtl"><head><title>My Test</title><style></style></head><body class="Test">This is some <strong>sample text</strong>.</body></html>',
		dataProcessor.ConvertToHtml( '<html dir="rtl"><head><title>My Test</title><style></style></head><body class="Test">This is some <strong>sample text</strong>.</body></html>' ) ) ;

	// Reset the config for other tests.
	FCKConfig.FullPage = false ;
}

function test_ConvertToHtml_Full_Incomplete()
{
	FCKConfig.FullPage = true ;

	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<html dir="ltr"><head><title></title></head><body>This is some <strong>sample text</strong>.</body></html>',
		dataProcessor.ConvertToHtml( 'This is some <strong>sample text</strong>.' ) ) ;

	// Reset the config for other tests.
	FCKConfig.FullPage = false ;
}

function test_ConvertToHtml_Full_Empty()
{
	FCKConfig.FullPage = true ;

	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<html dir="ltr"><head><title></title></head><body></body></html>',
		dataProcessor.ConvertToHtml( '' ) ) ;

	// Reset the config for other tests.
	FCKConfig.FullPage = false ;
}

function test_ConvertToHtml_Settings()
{
	FCKConfig.ContentLangDirection = 'rtl' ;
	FCKConfig.DocType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' ;
	FCKConfig.BodyId = 'TestId' ;
	FCKConfig.BodyClass = 'TestClass'

	var dataProcessor = new FCKDataProcessor() ;

	if ( navigator.userAgent.indexOf( 'MSIE' ) > -1 )	// IE
	{
		assertEquals(
			'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
			'<html dir="rtl" style="overflow-y: scroll"><head><title></title></head><body id="TestId" class="TestClass">This is some <strong>sample text</strong>.</body></html>',
			dataProcessor.ConvertToHtml( 'This is some <strong>sample text</strong>.' ) ) ;
	}
	else
	{
		assertEquals(
			'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
			'<html dir="rtl"><head><title></title></head><body id="TestId" class="TestClass">This is some <strong>sample text</strong>.</body></html>',
			dataProcessor.ConvertToHtml( 'This is some <strong>sample text</strong>.' ) ) ;
	}
	// Reset the config for other tests.
	FCKConfig.ContentLangDirection = 'ltr' ;
	FCKConfig.DocType = '' ;
	FCKConfig.BodyId = '' ;
	FCKConfig.BodyClass = ''
}

function test_ConvertToDataFormat_Exclude_NoFormat()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<p>This is a <strong>test</strong>.</p><p>Another paragraph.</p>',
		dataProcessor.ConvertToDataFormat( document.getElementById('xDiv1'), true ) ) ;
}

function test_ConvertToDataFormat_NoExclude_NoFormat()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<div id="xDiv1"><p>This is a <strong>test</strong>.</p><p>Another paragraph.</p></div>',
		dataProcessor.ConvertToDataFormat( document.getElementById('xDiv1'), false ) ) ;
}

function test_ConvertToDataFormat_NoExclude_Format()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<div id="xDiv1">\n<p>This is a <strong>test</strong>.</p>\n<p>Another paragraph.</p>\n</div>',
		dataProcessor.ConvertToDataFormat( document.getElementById('xDiv1'), false, false, true ) ) ;
}

function test_ConvertToDataFormat_IgnoreEmpty()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'',
		dataProcessor.ConvertToDataFormat( document.getElementById('xDiv2'), true, true ) ) ;
}

function test_ConvertToDataFormat_Character_Transform()
{
	var dataProcessor = new FCKDataProcessor() ;

	assertEquals(
		'<p>&lt;&lt;GetText(Edit)&gt;&gt;</p>',
		dataProcessor.ConvertToDataFormat( document.getElementById('xDiv3'), true, true ) ) ;
}

	</script>
</head>
<body>
	<div id="xDiv1"><p>This is a <strong>test</strong>.</p><p>Another paragraph.</p></div>
	<div id="xDiv2"><p>&nbsp;</p></div>
	<div id="xDiv3"><p>&lt;&lt;GetText(Edit)&gt;&gt;</p></div>
</body>
</html>
